package com.myappengine.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.myappengine.dao.StudentDAO;
import com.myappengine.exception.ObjectNotFoundException;
import com.myappengine.model.Clazz;
import com.myappengine.model.Instructor;
import com.myappengine.model.Student;
import com.myappengine.model.UploadedFile;

@Service
public class StudentService {
	
	@Autowired
	private StudentDAO studentDAO; 
	
	public void persistStudent(Student student) {
		studentDAO.persistStudent(student);
	}
	
	public List<Student> getAllStudents() {
		return studentDAO.getAllStudents();
	}
	
	public List<Clazz> getClassesByStudent(String studentKey) {
		return studentDAO.getClassesByStudent(studentKey);
	}
	
	public Student getStudentByKey(String studentKey) {
		return studentDAO.getStudentByKey(studentKey);
	}
	
	public void updateStudent(Student student) {
		studentDAO.updateStudent(student);
	}
	
	public void addStudentToClass(String studentKey, Clazz clazz) {
		studentDAO.addStudentToClass(studentKey, clazz);
	}
	
	public List<Student> getAllStudent() {
		return studentDAO.getAllStudent();
	}
	
	public void assignInstructorToStudent(String studentKey, Instructor instructor) {
		studentDAO.assignInstructorToStudent(studentKey, instructor);
	}
	
	public void addFileToStudent(String studentKey, UploadedFile file) {
		Student student = studentDAO.getStudentByKey(studentKey);
		if (student == null) {
			throw new ObjectNotFoundException();
		} else {
			System.out.println("call to DAO");
			studentDAO.addFileToStudent(studentKey, file);
		}
	}
	
	public void deleteStudent(String studentKey) {
		Student student = studentDAO.getStudentByKey(studentKey);
		if (student == null) {
			throw new ObjectNotFoundException();
		} else {
			studentDAO.deleteStudent(studentKey);
		}
	}
}
